package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.AreaChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**
 * @ClassName AreaChartDemo
 * @Description
 * @Author wangss
 * @date 2020.06.30 22:36
 * @Version 1.0
 */
public class AreaChartDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        AreaChart<Number, Number> areaChart = createChart();

        HBox hBox = new HBox(10);
        hBox.getChildren().addAll(areaChart);

        AnchorPane root = new AnchorPane();
        root.getChildren().addAll(hBox);

        Scene scene = new Scene(root);

        primaryStage.setScene(scene);
        primaryStage.setTitle("位移");
        primaryStage.setHeight(800d);
        primaryStage.setWidth(800d);
        primaryStage.show();
    }

    private AreaChart<Number, Number> createChart() {
        NumberAxis x = new NumberAxis("x轴", 0, 100, 10);
        NumberAxis y = new NumberAxis("y轴", 0, 100, 10);

        XYChart.Series<Number, Number> xy1 = new XYChart.Series<>();
        xy1.setName("xy1");

        XYChart.Series<Number, Number> xy2 = new XYChart.Series<>();
        xy2.setName("xy2");

        XYChart.Data<Number, Number> data1 = new XYChart.Data<>(10, 10);
        XYChart.Data<Number, Number> data2 = new XYChart.Data<>(20, 20);
        XYChart.Data<Number, Number> data3 = new XYChart.Data<>(30, 30);
        XYChart.Data<Number, Number> data4 = new XYChart.Data<>(40, 40);

        data1.setExtraValue(10);

        XYChart.Data<Number, Number> data5 = new XYChart.Data<>(24, 25);
        XYChart.Data<Number, Number> data6 = new XYChart.Data<>(76, 90);
        XYChart.Data<Number, Number> data7 = new XYChart.Data<>(80, 23);
        XYChart.Data<Number, Number> data8 = new XYChart.Data<>(90, 40);

        xy1.getData().addAll(data1, data2, data3, data4);
        xy2.getData().addAll(data5, data6, data7, data8);

        AreaChart<Number, Number> areaChart = new AreaChart<>(x, y);
        areaChart.getData().addAll(xy1, xy2);

//        areaChart.setCreateSymbols(true);

        return areaChart;
    }
}
